<?php
class Manager{
    public $link;
    function __construct($linkstr){
        $this->link = $linkstr;
    }
    
    
    public function getAllAdmin(){
        $strsql = "select * from tb_admin order by Id desc";
        $result = mysqli_query($this->link, $strsql);
        return mysqli_fetch_all($result);
    }
    
    public function getAllUser(){
        $strsql = "select * from tb_user order by Id desc";
        $result = mysqli_query($this->link, $strsql);
        return mysqli_fetch_all($result);
    }
    
    public function getAllShop(){
        $strsql = "select * from tb_shangpin left join tb_category on tb_shangpin.category = tb_category.Id order by tb_shangpin.id desc";
        $result = mysqli_query($this->link, $strsql);
        return mysqli_fetch_all($result);
    }
    
    public function getAllCategory(){
        $strsql = "select * from tb_category order  by Id asc";
        $result = mysqli_query($this->link, $strsql);
        return mysqli_fetch_all($result);
    }
    
    public function getAdminById($id){
        $strsql = "select * from tb_admin where id = ".$id;
        $result = mysqli_query($this->link, $strsql);
        $data = mysqli_fetch_all($result);
        return $data[0];
    }
    
    public function getUserById($id){
        $strsql = "select * from tb_user where id = ".$id;
        $result = mysqli_query($this->link, $strsql);
        $data = mysqli_fetch_all($result);
        return $data[0];
    }
    
    public function getShopById($id){
        $strsql = "select * from tb_shangpin left join tb_category on tb_shangpin.category = tb_category.Id where tb_shangpin.id = ".$id;
        $result = mysqli_query($this->link, $strsql);
        $data = mysqli_fetch_all($result);
        return $data[0];
    }
    
    public function getCategoryById($id){
        $strsql = "select * from tb_category  where id = ".$id;
        $result = mysqli_query($this->link, $strsql);
        $data = mysqli_fetch_all($result);
        return $data[0];
    }
    
    public function addAdmin($admin, $status,$password,$email,$phone){
        $strsql = "insert into tb_admin (ad_name, ad_status,ad_pwd,ad_email,ad_phone) values ('".$admin."', '".$status."', '".$password."', '".$email."', '".$phone."')";
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function addUser($admin,$password,$email,$phone){
        $strsql = "insert into tb_user (us_name, us_pwd,us_email,us_phone) values ('".$admin."', '".$password."', '".$email."', '".$phone."')";
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function addShop($name, $price,$o_price,$img,$descript,$category){
        $strsql = "insert into tb_shangpin (name, price,o_price,img,descript,category) values ('".$name."', '".$price."', '".$o_price."', '".$img."' , '".$descript."' , '".$category."')";
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function addCategory($Id,$name){
        $strsql = "insert into tb_category (Id,name) values ('".$Id."', '".$name."')";
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function editAdmin($admin, $status,$password,$email,$phone, $id){
        $strsql = "update tb_admin set ad_name = '".$admin."', ad_status = '".$status."' , ad_pwd = '".$password."' ,ad_email = '".$email."' ,ad_phone = '".$phone."'  where id = ".$id;
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function editUser($admin,$password,$email,$phone, $id){
        $strsql = "update tb_user set us_name = '".$admin."', us_pwd = '".$password."' ,us_email = '".$email."' ,us_phone = '".$phone."'  where id = ".$id;
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function editShop($name, $price,$o_price,$img,$descript,$category,$id){
        $strsql = "update tb_shangpin set name = '".$name."', price = '".$price."' ,o_price = '".$o_price."' ,img = '".$img."' ,descript = '".$descript."' ,category = '".$category."'  where id = ".$id;
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function editCategory($Id,$name,$id){
        $strsql = "update tb_category set Id = '".$Id."', name = '".$name."'  where id = ".$id;
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function deleteAdmin($id){
        $strsql = "delete from tb_admin where id = ".$id;
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function deleteUser($id){
        $strsql = "delete from tb_user where id = ".$id;
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function deleteShop($id){
        $strsql = "delete from tb_shangpin where id = ".$id;
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
    
    public function deleteCategory($id){
        $strsql = "delete from tb_category where id = ".$id;
        $query = mysqli_query($this->link, $strsql);
        if ($query){
            return true;
        }else{
            return false;
        }
    }
}











?>